/* Copyright (c) 2010, mitsuhisa.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of the misuhisa.net nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sstream>
#include "Object.hpp"
#include "String.hpp"
#include "StrPool.hpp"

namespace nyu {

Object::Object() {
}

Object::~Object() {
}

Value Object::getSlot(const char* name, Context& c) {
    return getSlot(StrPool::get(name, true), c);
}

Value Object::getSlot(Object* name, Context& c) {
    return getSlot(object_to_value(name), c);
}

Object::hash_code_type Object::hash() {
    return static_cast<hash_code_type>(reinterpret_cast<long>(this));
}

Object::hash_code_type Object::hash(Context& c) {
    return hash();
}

bool Object::isTrue(Context& c) {
    return true;
}

String* Object::toString(Context& c) {
    std::ostringstream ost;
    ost << "OBJECT(" << this << ")";
    return new DynamicString(ost.str());
}

int_type Object::toIntval(Context& c) {
    return 0;
}

Value Object::toInt(Context& c) {
    return int_to_value(toIntval(c));
}

Value Object::opCall(Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opAdd(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opSub(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opMul(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opDiv(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opMod(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opLShift(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opRShift(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opOr(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opXor(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

Value Object::opAnd(Value v, Context& c, bool is_tail) {
    return NULL_VALUE;
}

bool Object::opEq(Value v, Context& c, bool is_tail) {
    return object_to_value(this) == v;
}

bool Object::opNe(Value v, Context& c, bool is_tail) {
    return object_to_value(this) == v;
}

bool Object::opLt(Value v, Context& c, bool is_tail) {
    return false;
}

bool Object::opLe(Value v, Context& c, bool is_tail) {
    return false;
}

bool Object::opGt(Value v, Context& c, bool is_tail) {
    return false;
}

bool Object::opGe(Value v, Context& c, bool is_tail) {
    return false;
}

Value Object::opIAdd(Value name, Value v, Context& c, bool is_tail) {
    // TODO
    return NULL_VALUE;
}

Value Object::opGetItem(Value idx, Context& c, bool is_tail) {
    return getSlot(idx, c);
}

int_type Object::length(Context& c) {
    return 0;
}

Value Object::push(Context& c) {
    return NULL_VALUE;
}

Value Object::pop(Context& c) {
    return NULL_VALUE;
}

Value Object::each(Context& c) {
    return NULL_VALUE;
}

bool Object::revOpEq(String* other, Context& c, bool is_tail) {
    return false;
}

}
